package com.example.educate.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.example.educate.model.vod.Chapter;
import com.example.educate.model.vod.Video;
import com.example.educate.result.Result;
import com.example.educate.service.ChapterService;
import com.example.educate.service.VideoService;
import com.example.educate.vo.vod.ChapterVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author AT
 * @since 2022-09-18
 */
@Api(tags = "章节和小节接口")
@RestController
@RequestMapping("/admin/vod/chapter")
//@CrossOrigin
public class ChapterController {
    @Autowired
    private ChapterService chapterService;
    @Autowired
    private VideoService videoService;
    @ApiOperation("大纲列表")
    @GetMapping("getNestedTreeList/{courseId}")
    public Result getTreeList(@PathVariable Long courseId){
        List<ChapterVo> list=chapterService.getTreeList(courseId);
        return Result.ok(list);
    }
    @ApiOperation("添加章节")
    @PostMapping("saveChapter")
    public Result saveChapter(@RequestBody Chapter chapter){
        boolean save = chapterService.save(chapter);
        return Result.ok(save);
    }
    @ApiOperation("删除章节")
    @DeleteMapping("deleteChapter/{chapterId}")
    public Result deleteChapter(@PathVariable Long chapterId){
        boolean b = chapterService.removeById(chapterId);
        return Result.ok(b);
    }
    @ApiOperation("根据id查询章节")
    @GetMapping("getChapter/{id}")
    public Result getChapter(@PathVariable Long id){
        Chapter byId = chapterService.getById(id);
        return Result.ok(byId);
    }
    @ApiOperation("修改接口")
    @PutMapping("update")
    public Result update(@RequestBody Chapter chapter){
        boolean b = chapterService.updateById(chapter);
        return Result.ok(b);
    }
}

